﻿using BoriPeter.FitnessJournal8.Models;
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.FitnessJournal8.ViewModels
{
    public class DailyIntakeViewModel : ViewModelBase
    {
        #region Constructor
        public DailyIntakeViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            
        }
        #endregion

        #region SelectedEntry
        private DailyEntry selectedEntry;
        public DailyEntry SelectedEntry
        {
            get
            {
                return this.selectedEntry;
            }

            set
            {
                this.selectedEntry = value;
                NotifyOfPropertyChange("SelectedEntry");
                Navigate2DailyEntry(selectedEntry);
            }
        }
        #endregion

        #region Entries
        private ObservableCollection<DailyEntry> entries;
        public ObservableCollection<DailyEntry> Entries
        {
            get
            {
                return this.entries;
            }

            set
            {
                this.entries = value;
                NotifyOfPropertyChange("Entries");
            }
        }
        #endregion

        #region OnInitialize()
        protected override async void OnInitialize()
        {
            base.OnInitialize();
            var entryList = await NutritionSource.GetDailyEntryListAsync(DateTime.Now.AddMonths(-3), DAL.EntryService.CaloriesIntake);
            Entries = new ObservableCollection<DailyEntry>(entryList.Where(e => e.CaloriesIntakeKcal != 0).OrderByDescending(e => e.Date));
            ProgressBarIsIndeterminate = false;
        }
        #endregion
    }
}
